import {createApp, reactive} from 'vue'
import App from './App.vue'
import {router} from "./router/index.ts";
import ElementPlus from 'element-plus'
import {AXIOS_NAME,BTN_PERMISSION_KEY,MENU_ITEM_STATUS} from './constant/constant.ts'
import service from './utils/request.ts'
import 'element-plus/dist/index.css'

let app = createApp(App);
let menuItemStatus = reactive({});

const checkBtnPermission = (el,binding) =>{
    const strBtn = localStorage.getItem(BTN_PERMISSION_KEY);
    if(strBtn == null || strBtn == undefined || strBtn == ''){
        el.remove();
        return;
    }
    const btnArray = JSON.parse(strBtn);
    if(!btnArray.includes(binding.value)){
        el.remove();
    }
}
app.directive("check-permission",checkBtnPermission);
app.provide(MENU_ITEM_STATUS,menuItemStatus);
app.provide(AXIOS_NAME,service);
app.use(ElementPlus);
app.use(router);
app.mount('#app');

Array.prototype.pushAll = function (array){
    array.forEach((item) => {
       this.push(item);
    });
}

Array.prototype.clear = function (){
    this.splice(0,this.length);
}
